package threading;


import java.time.LocalDateTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TestDemo28 {
    public static void main1(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            int num = i;
            executorService.submit(() -> {
                System.out.println("i:" + num + "线程名字：" + Thread.currentThread().getName());
            });
        }
    }

    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);
        System.out.println("添加任务时间:" + LocalDateTime.now());
        // 执行定时任务（延迟3s执行）只执行一次
        scheduledExecutorService.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("执行子任务时间:" + LocalDateTime.now());
            }
        },3, TimeUnit.SECONDS);
    }
}
